package com.xiaofeixia.sj.serviceimpl;

import cn.hutool.http.HttpUtil;
import cn.hutool.json.JSON;
import cn.hutool.json.JSONUtil;
import cn.hutool.json.JSONObject;
import com.xiaofeixia.sj.service.UserService;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import java.io.Console;


@Service("userService")
public class UserServiceImpl implements UserService {

    @Value("${origin}")
    private String origin;

    @Value("${appkey}")
    private String appkey;

    /**
     * 登陆
     *
     * @param username
     * @param password
     * @return
     */
    @Override
    public JSON UserLogin(String username, String password) {
        String url = origin + "/api/User/UserLogin/username=" + username + "&password=" + password + "&appkey=" + appkey;
        String post = HttpUtil.post(url, username);
        JSONObject  jsonObject1 = JSONUtil.parseObj(post);
        JSON json = JSONUtil.parse(post);
        JSONUtil.toJsonStr(json);

        Object id =  jsonObject1.get("id");

//        Object id = jsonObject1.get("id");
        Object user_name = jsonObject1.get("user_name");
        Boolean isjson = JSONUtil.isJson(post);
        cn.hutool.core.lang.Console.log("isJOSN"+isjson);
        Object passwords = jsonObject1.get("password");

        cn.hutool.core.lang.Console.log(id);
        cn.hutool.core.lang.Console.log(user_name);
        cn.hutool.core.lang.Console.log(passwords);

        System.out.println("post---->"+post);
        return json;
    }
}
